<?php
class UserModel extends Model{
	private $table;
	public $loginUser;
	
	public function __construct(){
		parent::__construct();
		
		$this->table = C('db_table_prefix').'user';
		$this->loginUser = $_SESSION['tiny']['LoginUser'];
	}
	
	public function checkLogin(){		
		if( empty($this->loginUser['userid']) ){
			return false;
		}
		return true;	
	}
	
	public function login($uname,$passwd){
		$passwd = md5($passwd);
		$sql = "SELECT * FROM `{$this->table}` WHERE `username`='{$uname}' AND  `passwd`='{$passwd}'";
		$user = $this->query($sql);
	
		return $user[0];
	}
	
	public function logout(){
		unset($_SESSION['tiny']['LoginUser']);
		$url = C('backend') . 'login.php';
		redirect($url);
	}
	
}